<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Notice extends Model
{
    //
    protected $table = 'notice';

    protected $fillable  = ['title','content','type','uid','model','post_id','status'];

    protected function getDateFormat()
    {
        return 'U';
    }

    public function user(){
        return $this->hasOne('App\Models\User','uid','uid');
    }

    static function getCommonInfo($notice){
        $res = array();
        if(!empty($notice)){
            $res['id'] = $notice->id;
            $res['title'] = $notice->title;
            $res['content'] = $notice->content;
            $res['pubtime'] = date('m月d日',strtotime($notice->created_at)); //发布时间
            $res['datetime'] = date('Y-m-d',strtotime($notice->created_at));
            $res['time'] = date('H:i:s',strtotime($notice->created_at));
            if($notice->type==1) $type = '无界投融官方公告';else if($notice->type==2) $type = '项目公告';else if($notice->type==3) $type = '活动公告';else if($notice->type==4) $type = '直通车公告';
            $res['type'] = $type;
            $res['username'] = $notice->user->realname ? : $notice->user->nickname;
        }
        return $res;
    }
    static function registerNotice($user){
        $res = array();
        if(isset($user)){
            $res['title'] = trans('webNotice.welcomeRegWjtr.title');
            $res['content'] = htmlspecialchars(trans('webNotice.welcomeRegWjtr.content',['url1' => '/user/project/create']));
            $res['type'] = 1;
            $res['uid'] = $user->uid;
        }
        return $res;
    }
}
